<?php
namespace slinks\extensions\action\result;

use slinks\extensions\action\core\IActionContext;

use slinks\extensions\action\configuration\IResultMapping;

/**
 * Renders the result as a template. Using the configured Slinks template engine.
 * 
 * @author Navid Mitchell
 *
 */
class ViewRenderingResult implements IResult {
	
	/**
	 * The configured template render engine.
	 * @var EngineInterface
	 */
	private $renderEngine;
	
	/**
	 * Executes the given result. 
	 * 
	 * @param IResultMapping $resultMapping
	 * @param ParameterBagInterface $parameters
	 */
	public function execute(IResultMapping $resultMapping,IActionContext $actionContext){
            return $this->renderEngine->render($resultMapping->getValue(),$actionContext->getValueStack()->all());
	}

	
	/**
	 * Sets the configured render engine
	 * @param EngineInterface $renderEngine
	 * @Inject 
	 */
	public function setRenderEngine(\slinks\core\Templating\EngineInterface $renderEngine){
	    $this->renderEngine = $renderEngine;
	}
}